package Deom;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2023-11-26
 * Time: 11:01
 */
public class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    Student[] students = new Student[3];

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
    //这是以姓名来判断
    @Override
    public int compareTo(Student o) {
        return this.name.compareTo(o.name);
    }
    //这是以年龄来判断
    /*@Override
    public int compareTo(Student o) {
        return this.age-o.age;
    }*/
    public static void main(String[] args) {
       /* Student student1 =new Student("zhangsan",19);
        Student student2 =new Student("lisi",29);
        if(student1.compareTo(student2)>0) {
            System.out.println("student1>student2");
        } else {
            System.out.println("student1<=student2");
        }*/
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan",18);
        students[1] = new Student("lisi",19);
        students[2] = new Student("zhaowu",20);
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
        /*if(students[0].compareTo(students[1])>0) {
            System.out.println("student[0]>student[1]");
        } else {
            System.out.println("student[0]<=student[1]");
        }*/
    }
}
